<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>表单组合</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="{{ADMIN_PATH}}layui/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="{{ADMIN_PATH}}layui/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="{{ADMIN_PATH}}js/admin.common.js" media="all">
    <style>
        .layui-upload-img {
            width: 92px;
            height: 92px;
            margin: 0 10px 10px 0;
        }
    </style>
</head>
<body>


<div class="layui-card">

    <form class="layui-form layui-form-pane" action="" lay-filter="component-form-group">
        <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title">
                <li class="layui-this">产品基础信息</li>
                <li>产品规格</li>
                <li>详细内容</li>

            </ul>
            <div class="layui-tab-content">

                <div class="layui-tab-item  layui-show">
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品分类</label>
                        <div class="layui-input-inline">
                            <select name="gc_id" lay-verify="">
                                <option value="">请选择分类</option>
                                @foreach($goods_class_list as $gck=>$gcv)
                                    <option value="{{$gcv->id}}"
                                            @if($gcv->id==$goods->gc_id)selected="selected"@endif >{{$gcv->name}}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">产品名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="goods_name" value="{{$goods->goods_name}}" lay-verify="title"
                                   autocomplete="off"
                                   placeholder="请输入标题" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">商品卖点</label>
                        <div class="layui-input-block">
                            <textarea name="goods_jingle" placeholder="请输入内容"
                                      class="layui-textarea">{{$goods->goods_jingle}}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">市场价</label>
                            <div class="layui-input-inline">
                                <input type="text" name="goods_marketprice" value="{{$goods->goods_marketprice}}"
                                       lay-verify="title" autocomplete="off"
                                       placeholder="￥" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">成本价</label>
                            <div class="layui-input-inline">
                                <input type="text" name="goods_price" value="{{$goods->goods_price}}" lay-verify="title"
                                       autocomplete="off"
                                       placeholder="￥" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品图片</label>
                        <div class="layui-input-inline">
                            <input name="goods_image" value="{{$goods->goods_image}}" lay-verify="required"
                                   id="LAY_avatarSrc" placeholder="图片地址"
                                   class="layui-input">
                        </div>
                        <div class="layui-input-inline layui-btn-container" style="width: auto;">
                            <button type="button" class="layui-btn layui-btn-primary test" id="LAY_avatarUpload">
                                <i class="layui-icon">&#xe67c;</i>上传图片
                            </button>
                            <button class="layui-btn layui-btn-primary" layadmin-event="avartatPreview">查看图片</button>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">商品库存</label>
                            <div class="layui-input-block">
                                <input type="text" name="goods_storage" value="{{$goods->goods_storage}}"
                                       lay-verify="goods_storage" autocomplete="off"
                                       placeholder="请输入商品库存" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">库存预警值</label>
                            <div class="layui-input-block">
                                <input type="text" name="goods_storage_alarm" value="{{$goods->goods_storage_alarm}}"
                                       lay-verify="goods_storage_alarm" autocomplete="off"
                                       placeholder="请输入标题" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label"> 商家货号</label>
                            <div class="layui-input-block">
                                <input type="text" name="goods_serial" value="{{$goods->goods_serial}}"
                                       lay-verify="goods_serial" autocomplete="off"
                                       placeholder="请输入标题" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">商品推荐</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="goods_commend"
                                   {{$goods->goods_commend?'checked':''}} lay-skin="switch" lay-text="开启|关闭">
                        </div>
                    </div>


                </div>
                <div class="layui-tab-item ">
                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">多图选择</label>
                        <div class="layui-input-inline">
                            <input type="checkbox" id="select_upload_type" name="upload_type" lay-skin="switch"
                                   lay-filter="component-form-switchuploadtype"
                                   {{$goods->upload_type?'checked':''}} lay-text="开启|关闭">
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid layui-word-aux">当开启时每个规格产品将对应上传图片组，关闭一个商品类型只传一个图片组</div>
                        </div>
                    </div>

                    <div id="spec" lass="layui-form">
                        @foreach($spec_list as $sk=>$sp_vo)
                            <div class="layui-form-item spec_li" pane>
                                <label class="layui-form-label">{{$sp_vo->name}}</label>
                                <input type="hidden" name="sp_name[{{$sk}}]" value="{{$sp_vo->name}}">
                                <div class="layui-input-block">
                                    @if(!empty($sp_vo->value))
                                        @foreach($sp_vo->value as $sp_vk=>$sp_v)
                                            <span class="li"> <input type="checkbox"
                                                                     name="sp_val[{{$sk}}][{{$sp_v->id}}]"
                                                                     lay-skin="primary" nc_type="{{$sp_v->id}}"
                                                                     value="{{$sp_v->name}}"
                                                                     title="{{$sp_v->name}}"
                                                                     @if(in_array($sp_v->id,array_keys($goods->spec_value[$sk]))) checked="checked"@endif></span>
                                        @endforeach
                                    @endif
                                </div>
                            </div>
                        @endforeach
                    </div>
                    <div id="spec_table">

                       @if (!empty($goods->spec_name))

                        <div class="layui-card">
                            <div class="layui-card-header">库存配置</div>
                            <div class="layui-card-body">
                                <table class="layui-table table-bordered">
                                    <thead>
                                    <tr>
                                       @foreach($goods->spec_name as $spk=>$spv)
                                        <th>{{$spv}}</th>
                                       @endforeach
                                        <th>市场价</th>
                                        <th>销售价格</th>
                                        <th>库存</th>
                                        <th>预警值</th>
                                        <th>商家货号</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @if (!empty($goods['spec_list']))
                                        @foreach($goods['spec_list'] as $gsk=> $gsv)

                                    <tr>
                                        @foreach($gsv['goods_spec'] as $gkk=> $gvv)
                                        <input type="hidden" name="spec[{{$gsk}}][sp_value][{{$gkk}}]" value="{{$gvv}}">
                                        <td>{{$gvv}}</td>
                                        @endforeach
                                        <td><input type="hidden" name="spec[{{$gsk}}][upload_id]" value="221">
                                            <div class="layui-input-inline"><input class="layui-input" type="text"
                                                                                   name="spec[{{$gsk}}][marketprice]"
                                                                                 value="{{$gsv["goods_marketprice"]}}"  placeholder="￥"></div>
                                        </td>
                                        <td>
                                            <div class="layui-input-inline"><input class="layui-input" type="text"
                                                                                   name="spec[{{$gsk}}][price]"
                                                                                   value="{{$gsv["goods_price"]}}"     placeholder="￥"></div>
                                        </td>
                                        <td>
                                            <div class="layui-input-inline"><input class="layui-input" type="text"
                                                                                   value="{{$gsv["goods_storage"]}}"        name="spec[{{$gsk}}][stock]">
                                            </div>
                                        </td>
                                        <td>
                                            <div class="layui-input-inline"><input class="layui-input" type="text"
                                                                                   value="{{$gsv["goods_storage_alarm"]}}"       name="spec[{{$gsk}}][alarm]">
                                            </div>
                                        </td>
                                        <td>
                                            <div class="layui-input-inline"><input class="layui-input" type="text"
                                                                                   value="{{$gsv["goods_serial"]}}"      name="spec[{{$gsk}}][sku]"></div>
                                        </td>
                                    </tr>
                                        @endforeach
                                    @endif
                                    </tbody>
                                </table>
                            </div>
                        </div>

                     @endif

                    </div>

                    <div class="layui-form-item">
                        <div id="upload_img_box">


                            <div class="layui-card">
                                <div class="layui-card-header">上传默认图</div>
                                <div class="layui-card-body">
                                    <table class="layui-table table-bordered">
                                        <thead>
                                        <tr>
                                            <th>上传图片1</th>
                                            <th>上传图片2</th>
                                            <th>上传图片3</th>
                                            <th>上传图片4</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr>
                                            <td><input type="hidden" name="default_upload_muilt[0][]"
                                                       class="img_input_val" value="">
                                                <div class="layui-input-inline">
                                                    <button type="button" class="layui-btn layui-btn-primary test"
                                                            id="test_defalut_one">
                                                        <i class="layui-icon"></i>上传图片
                                                    </button>
                                                    <input class="layui-upload-file" type="file" accept="undefined">
                                                </div>
                                            </td>
                                            <td><input type="hidden" name="default_upload_muilt[0][]"
                                                       class="img_input_val" value="">
                                                <div class="layui-input-inline">
                                                    <button type="button" class="layui-btn test" id="test_defalut_two">
                                                        上传图片
                                                    </button>
                                                    <input class="layui-upload-file" type="file" accept="undefined">
                                                    <button class="layui-btn layui-btn-primary"
                                                            layadmin-event="avartatPreview">查看
                                                    </button>
                                                </div>
                                            </td>
                                            <td><input type="hidden" name="default_upload_muilt[0][]"
                                                       class="img_input_val" value="">
                                                <div class="layui-input-inline">
                                                    <button type="button" class="layui-btn test"
                                                            id="test_defalut_third">
                                                        上传图片
                                                    </button>
                                                    <input class="layui-upload-file" type="file" accept="undefined">
                                                    <button class="layui-btn layui-btn-primary"
                                                            layadmin-event="avartatPreview">查看
                                                    </button>
                                                </div>
                                            </td>
                                            <td><input type="hidden" name="default_upload_muilt[0][]"
                                                       class="img_input_val" value="">
                                                <div class="layui-input-inline">
                                                    <button type="button" class="layui-btn test" id="test_defalut_four">
                                                        上传图片
                                                    </button>
                                                    <input class="layui-upload-file" type="file" accept="undefined">
                                                    <button class="layui-btn layui-btn-primary"
                                                            layadmin-event="avartatPreview">查看
                                                    </button>
                                                </div>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>



                        </div>
                    </div>

                </div>
                <div class="layui-tab-item">
                    <textarea id="goods_body" name="goods_body" style="display: none;">{{$goods->goods_body}}</textarea>
                </div>
                <div class="layui-form-item layui-hide">
                    <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit"
                           id="layuiadmin-app-form-submit" value="确认添加">
                    <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit"
                           value="确认编辑">
                </div>
            </div>
        </div>
    </form>


</div>


<script src="{{ADMIN_PATH}}layui/layuiadmin/layui/layui.js?{{time()}}"></script>
<script src="{{ADMIN_PATH}}jquery/dist/jquery.js?{{time()}}"></script>
<script>

    var add_url = '{{url('admin/shop/goods/add')}}';
    var uplaod_type_isflat = false;
    var layui_uplaod_gload;
    var uploadhtml = '<div class="layui-card">\n' +
        '                                <div class="layui-card-header">上传默认图</div>\n' +
        '                                <div class="layui-card-body">\n' +
        '                                    <table class="layui-table table-bordered">\n' +
        '                                        <thead>\n' +
        '                                        <tr>\n' +
        '                                            <th>上传图片1</th>\n' +
        '                                            <th>上传图片2</th>\n' +
        '                                            <th>上传图片3</th>\n' +
        '                                            <th>上传图片4</th>\n' +
        '                                        </tr>\n' +
        '                                        </thead>\n' +
        '                                        <tbody>\n' +
        '                                        <tr>\n' +
        '                                            <td><input type="hidden" name="default_upload_muilt[0][]" class="img_input_val" value=""/>\n' +
        '                                                <div class="layui-input-inline">\n' +
        '                                                    <button type="button" class="layui-btn layui-btn-primary test"\n' +
        '                                                            id="test_defalut_one">\n' +
        '                                                        <i class="layui-icon"></i>上传图片\n' +
        '                                                    </button>\n' +
        '                                                    <input class="layui-upload-file" type="file" accept="undefined"\n' +
        '                                                           name="file"></div>\n' +
        '                                            </td>\n' +
        '                                            <td><input type="hidden" name="default_upload_muilt[0][]" class="img_input_val" value=""/>\n' +
        '                                                <div class="layui-input-inline">\n' +
        '                                                    <button type="button" class="layui-btn" id="test_defalut_two">上传图片\n' +
        '                                                    </button>\n' +
        '                                                    <input class="layui-upload-file" type="file" accept="undefined"\n' +
        '                                                           name="file">\n' +
        '                                                    <button class="layui-btn layui-btn-primary"\n' +
        '                                                            layadmin-event="avartatPreview">查看\n' +
        '                                                    </button>\n' +
        '                                                </div>\n' +
        '                                            </td>\n' +
        '                                            <td><input type="hidden" name="default_upload_muilt[0][]"  class="img_input_val" value=""/>\n' +
        '                                                <div class="layui-input-inline">\n' +
        '                                                    <button type="button" class="layui-btn" id="test_defalut_third">\n' +
        '                                                        上传图片\n' +
        '                                                    </button>\n' +
        '                                                    <input class="layui-upload-file" type="file" accept="undefined"\n' +
        '                                                           name="file">\n' +
        '                                                    <button class="layui-btn layui-btn-primary"\n' +
        '                                                            layadmin-event="avartatPreview">查看\n' +
        '                                                    </button>\n' +
        '                                                </div>\n' +
        '                                            </td>\n' +
        '                                            <td><input type="hidden" name="default_upload_muilt[0][]" class="img_input_val" value=""/>\n' +
        '                                                <div class="layui-input-inline">\n' +
        '                                                    <button type="button" class="layui-btn" id="test_defalut_four">上传图片\n' +
        '                                                    </button>\n' +
        '                                                    <input class="layui-upload-file" type="file" accept="undefined"\n' +
        '                                                           name="file">\n' +
        '                                                    <button class="layui-btn layui-btn-primary"\n' +
        '                                                            layadmin-event="avartatPreview">查看\n' +
        '                                                    </button>\n' +
        '                                                </div>\n' +
        '                                            </td>\n' +
        '                                        </tr>\n' +
        '                                        </tbody>\n' +
        '                                    </table>\n' +
        '                                </div>\n' +
        '                            </div>';
    layui.config({
        base: '{{ADMIN_PATH}}layui/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate', 'layedit', 'upload'], function () {
        var $ = layui.$
            , layedit = layui.layedit
            , admin = layui.admin
            , element = layui.element
            , layer = layui.layer
            , laydate = layui.laydate
            , form = layui.form;

        //====================获取访问token=======================
        var localToken = layui.data('token');
        //====================编辑器上传设置============================
        layedit.set({
            uploadImage: {
                url: '/public/upload/pic', //接口url
                headers: {token: localToken.access_token}
            }
        });
        form.on('submit(layuiadmin-app-form-submit)', function (data) {
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.post(add_url, data.field, successb, "json");
            return false;
            parent.layui.table.reload('test-table-reload'); //重载表格
            parent.layer.close(index); //再执行关闭
        });

        function successb(data) {
            //console.log(data);
            if (data.status == 200) {
                layer.msg("操作成功", {icon: 6});
            } else {
                layer.msg(data.message, {icon: 5});
            }
        }

        form.on('switch(component-form-switchuploadtype)', function (data) {
            var uplaod_status = data.elem.checked;
            //console.log(uplaod_status);
            if (uplaod_status) {
                if (results.length > 0) {
                    layer.msg("有选项不能打开");
                    form.val('component-form-group', {upload_type: false});
                    return false;
                }
            } else {
                if (results.length > 0) {
                    layer.msg("有选项不能关闭");
                    form.val('component-form-group', {upload_type: true});
                    return false;
                } else {
                    $("#upload_img_box").html(uploadhtml);
                }
                layui_uplaod_gload.render({
                    elem: '#test_defalut_one'
                    , url: '/public/upload/pic'
                    , multiple: true
                    , before: function (obj) {
                        //预读本地文件示例，不支持ie8
                    }
                    , done: function (res) {
                        var item = this.item;
                        if (res.status == 200) {
                            // $('#test-upload-more-list').append('<img src="' + res.data.token + '" alt="' + res.data.token + '" class="layui-upload-img">')

                            item.closest("td").find(".img_input_val").val(res.data.id);
                        } else {
                            layer.msg("上传失败");
                        }
                        //上传完毕
                    }
                });
                layui_uplaod_gload.render({
                    elem: '#test_defalut_four'
                    , url: '/public/upload/pic'
                    , multiple: true
                    , before: function (obj) {
                        //预读本地文件示例，不支持ie8
                    }
                    , done: function (res) {
                        var item = this.item;
                        if (res.status == 200) {
                            // $('#test-upload-more-list').append('<img src="' + res.data.token + '" alt="' + res.data.token + '" class="layui-upload-img">')

                            item.closest("td").find(".img_input_val").val(res.data.id);
                        } else {
                            layer.msg("上传失败");
                        }
                        //上传完毕
                    }
                });
                layui_uplaod_gload.render({
                    elem: '#test_defalut_two'
                    , url: '/public/upload/pic'
                    , multiple: true
                    , before: function (obj) {
                        //预读本地文件示例，不支持ie8
                    }
                    , done: function (res) {
                        var item = this.item;
                        if (res.status == 200) {
                            // $('#test-upload-more-list').append('<img src="' + res.data.token + '" alt="' + res.data.token + '" class="layui-upload-img">')
                            item.closest("td").find(".img_input_val").val(res.data.id);
                        } else {
                            layer.msg("上传失败");
                        }
                        //上传完毕
                    }
                });
                layui_uplaod_gload.render({
                    elem: '#test_defalut_third'
                    , url: '/public/upload/pic'
                    , multiple: true
                    , before: function (obj) {
                        //预读本地文件示例，不支持ie8
                    }
                    , done: function (res) {
                        var item = this.item;
                        if (res.status == 200) {
                            // $('#test-upload-more-list').append('<img src="' + res.data.token + '" alt="' + res.data.token + '" class="layui-upload-img">')

                            item.closest("td").find(".img_input_val").val(res.data.id);
                        } else {
                            layer.msg("上传失败");
                        }
                        //上传完毕
                    }
                });

            }
            uplaod_type_isflat = uplaod_status;
            return false;
        });
        layedit.build('goods_body'); //建立编辑器
        var $ = layui.jquery;
        var upload = layui.upload;
        layui_uplaod_gload = layui.upload;

        //单上传
        upload.render({
            elem: '.test'
            , url: '/public/upload/pic' //上传接口
            , before: function (obj) {
            }
            , done: function (res, index, upload) {
                //获取当前触发上传的元素，一般用于 elem 绑定 class 的情况，注意：此乃 layui 2.1.0 新增
                var item = this.item;
                item.closest("td").find(".img_input_val").val(res.data.id);
            }
        });
    });
</script>

<script type="text/javascript">


    var array = [];
    var results = new Array();  //存放结果集
    //创建一个数组
    var len = array.length;  //长度为3
    var indexs = {};
    var myspec_value = [];   //存放属性值


    //网上拷贝意思不明
    function GetResults(start) {

        start++;
        if (start > len - 1) {  //说明array数组里有值
            return;
        }

        if (!indexs[start]) {
            //alert("----==->"+indexs[start]);
            indexs[start] = 0;
        }
        if (!(array[start] instanceof Array)) {  //判断类型－用途将不是数组变为数组
            array[start] = [array[start]];
        }
        for (indexs[start] = 0; indexs[start] < array[start].length; indexs[start]++) {
            GetResults(start);
            if (start == len - 1) {   //这个意思最后一次循环相等
                var temp = [];
                var mytemp = [];
                var subtempval = [];
                for (var i = len - 1; i >= 0; i--) {
                    if (!(array[start - i] instanceof Array)) {
                        array[start - i] = [array[start - i]];
                    }
                    temp.push(array[start - i][indexs[start - i]]);
                    //temp.push(myspec_value[start - i][indexs[start - i]]);
                    mytemp.push(myspec_value[start - i][indexs[start - i]]);
                    subtempval.push(myspec_value[start - i][indexs[start - i]]);
                }

                var mytempstring = mytemp.join("");
                temp.push(mytempstring);
                temp.push(subtempval);

                results.push(temp);
            }
        }
    }

    function spec_li_list() {
        var arr = new Array();
        var arr_val = new Array();
        var is = 0;
        $(".spec_li", "#spec").each(function () {

            var arr_li = new Array();
            var arr_li_val = new Array();
            $(".li", $(this)).each(function () {

                if ($(this).find("input").is(":checked")) {

                    arr_li.push($(this).find("input").val());
                    arr_li_val.push($(this).find("input").attr("nc_type"));
                }
            });
            arr[is] = new Array();
            arr[is] = arr_li;
            arr_val[is] = new Array();
            arr_val[is] = arr_li_val;
            is++;
        });
        myspec_value = arr_val;

        return arr;
    }

    $(".li", "#spec").bind("click", function () {

        $("#spec_table").html("");
        array = spec_li_list();
        results = new Array();
        //创建一个数组
        len = array.length;
        indexs = {};
        GetResults(-1);

        if (results.length > 0) {    //创建表格
            var vhtml = '<div class="layui-card">\
                                 <div class="layui-card-header">库存配置</div>\
                                     <div class="layui-card-body">\
                                    <table class="layui-table table-bordered">\
                                <thead>\
                                <tr>';
            $(".spec_li", "#spec").each(function () {
                vhtml = vhtml + '<th>' + $(this).find("label").text() + '</th>';
            });
            var vhtml = vhtml + '<th>市场价</th>\
                                  <th>销售价格</th>\
                                  <th>库存</th>\
                                  <th>预警值</th>\
                                  <th>商家货号</th>\
                                </tr>\
                              </thead>\
                              <tbody>\
                              </tbody>\
                            </table></div></div>';
            $("#spec_table").html(vhtml);

        } else {
            $("#upload_img_box").html(uploadhtml);

            layui_uplaod_gload.render({
                elem: '#test_defalut_one'
                , url: '/public/upload/pic'
                , multiple: true
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                }
                , done: function (res) {
                    var item = this.item;
                    if (res.status == 200) {
                        // $('#test-upload-more-list').append('<img src="' + res.data.token + '" alt="' + res.data.token + '" class="layui-upload-img">')

                        item.closest("td").find(".img_input_val").val(res.data.id);
                    } else {
                        layer.msg("上传失败");
                    }
                    //上传完毕
                }
            });
            layui_uplaod_gload.render({
                elem: '#test_defalut_four'
                , url: '/public/upload/pic'
                , multiple: true
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                }
                , done: function (res) {
                    var item = this.item;
                    if (res.status == 200) {
                        // $('#test-upload-more-list').append('<img src="' + res.data.token + '" alt="' + res.data.token + '" class="layui-upload-img">')

                        item.closest("td").find(".img_input_val").val(res.data.id);
                    } else {
                        layer.msg("上传失败");
                    }
                    //上传完毕
                }
            });
            layui_uplaod_gload.render({
                elem: '#test_defalut_two'
                , url: '/public/upload/pic'
                , multiple: true
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                }
                , done: function (res) {
                    var item = this.item;
                    if (res.status == 200) {
                        // $('#test-upload-more-list').append('<img src="' + res.data.token + '" alt="' + res.data.token + '" class="layui-upload-img">')

                        item.closest("td").find(".img_input_val").val(res.data.id);
                    } else {
                        layer.msg("上传失败");
                    }
                    //上传完毕
                }
            });
            layui_uplaod_gload.render({
                elem: '#test_defalut_third'
                , url: '/public/upload/pic'
                , multiple: true
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                }
                , done: function (res) {
                    var item = this.item;
                    if (res.status == 200) {
                        // $('#test-upload-more-list').append('<img src="' + res.data.token + '" alt="' + res.data.token + '" class="layui-upload-img">')

                        item.closest("td").find(".img_input_val").val(res.data.id);
                    } else {
                        layer.msg("上传失败");
                    }
                    //上传完毕
                }
            });

        }
        console.log(results);
        for (var a = 0; a < results.length; a++) {
            var table_td = "<tr>";
            var t_spec = "i_";

            for (var mm = 0; mm < len; mm++) {
                table_td = table_td + '<input type="hidden" name="spec[' + t_spec + results[a][len] + '][sp_value][' + results[a][len + 1][mm] + ']" value="' + results[a][mm] + '"/><td>' + results[a][mm] + "</td>";
            }
            //var table_td=table_td+'<input type="hidden" name="spec['+t_spec+results[a][len]+']" value=""/>';
            table_td = table_td + '<td><input type="hidden" name="spec[' + t_spec + results[a][len] + '][upload_id]"  value="' + results[a][4][0] + '"/> <div class="layui-input-inline">\
                            <input class="layui-input" type="text" name="spec[' + t_spec + results[a][len] + '][marketprice]" placeholder="￥">\
                          </div></td>\
                                  <td><div class="layui-input-inline">\
                            <input class="layui-input" type="text"  name="spec[' + t_spec + results[a][len] + '][price]" placeholder="￥">\
                          </div></td>\
                                  <td><div class="layui-input-inline">\
                            <input class="layui-input" type="text" name="spec[' + t_spec + results[a][len] + '][stock]">\
                          </div></td>\
                                  <td><div class="layui-input-inline">\
                            <input class="layui-input" type="text" name="spec[' + t_spec + results[a][len] + '][alarm]">\
                           </div></td>\
                                  <td><div class="layui-input-inline">\
                            <input class="layui-input" type="text" name="spec[' + t_spec + results[a][len] + '][sku]">\
                            </div></td>';
            table_td = table_td + "</tr>";
            $("#spec_table").find("tbody").append(table_td);
        }

        //图片组......上传图片数量
        if (uplaod_type_isflat) {

            var upload_arr = new Array();  //存放上传图片个数
            var upload_arr_val = new Array();//存放对应值
            if (results.length > 0) {    //创建表格

                $(".li", $("#spec .spec_li:eq(0)")).each(function () {
                    if ($(this).find("input").is(":checked")) {
                        upload_arr.push($(this).find("input").val());
                        upload_arr_val.push($(this).find("input").attr("nc_type"));
                        //vhtml=vhtml+'<th>'+$(this).find("input").val()+'</th>';

                    }
                });
                var vhtml = '<div class="layui-card">\
                                 <div class="layui-card-header">上传多图</div>\
                                     <div class="layui-card-body">\
                                    <table class="layui-table table-bordered">\
                                <thead>\
                                <tr>';
                //$(".spec_li",$("#spec .spec_li:eq(0)")).each(function () {
                vhtml = vhtml + '<th>' + $("#spec .spec_li:eq(0)").find("label").text() + '</th>';
                // });
                var v = 0;
                $(".li", $("#spec .spec_li:eq(0)")).each(function () {
                    if ($(this).find("input").is(":checked")) {
                        //vhtml=vhtml+'<th>'+$(this).find("input").val()+'</th>';
                        v++;
                    }
                });
                var vhtml = vhtml + '<th>上传图片1</th>\
                                  <th>上传图片2</th>\
                                  <th>上传图片3</th>\
                                  <th>上传图片4</th>\
                                </tr>\
                              </thead>\
                              <tbody>\
                              </tbody>\
                            </table></div></div>';
                $("#upload_img_box").html(vhtml);

            }
            //console.log(results);
            for (var a = 0; a < upload_arr.length; a++) {
                var table_td = "<tr>";
                var t_spec = "i_";

                //for(var mm=0;mm<1;mm++){
                table_td = table_td + "<td>" + upload_arr[a] + "</td>";
                ///  }
                //var table_td=table_td+'<input type="hidden" name="spec['+t_spec+results[a][len]+']" value=""/>'; onclick="uploadfile(\'#upload_id_'+a+'\')"
                table_td = table_td + '<td><input type="hidden" name="default_upload_muilt[' + upload_arr_val[a] + '][]" class="img_input_val"/><div class="layui-input-inline">\
                              <button type="button" class="layui-btn layui-btn-primary test" id="upload_id_one_' + a + '" >\n' +
                    '                                    <i class="layui-icon">&#xe67c;</i>上传图片\n' +
                    '                                </button>\
                                              </div></td>\
                                                      <td><input type="hidden" name="default_upload_muilt[' + upload_arr_val[a] + '][]" class="img_input_val"/><div class="layui-input-inline">\
                                      <button type="button" class="layui-btn" id="upload_id_two_' + a + '" >上传图片</button>\
                                  <button class="layui-btn layui-btn-primary" layadmin-event="avartatPreview">查看</button >\
                                  </div></td>\
                                                      <td><input type="hidden" name="default_upload_muilt[' + upload_arr_val[a] + '][]" class="img_input_val"/><div class="layui-input-inline">\
                                      <button type="button" class="layui-btn" id="upload_id_third_' + a + '" >上传图片</button>\
                                  <button class="layui-btn layui-btn-primary" layadmin-event="avartatPreview">查看</button >\
                                  </div></td>\
                                                      <td><input type="hidden" name="default_upload_muilt[' + upload_arr_val[a] + '][]" class="img_input_val"/><div class="layui-input-inline">\
                                      <button type="button" class="layui-btn" id="upload_id_four_' + a + '" >上传图片</button>\
                                  <button class="layui-btn layui-btn-primary" layadmin-event="avartatPreview">查看</button >\
                                  </div></td>';
                table_td = table_td + "</tr>";
                $("#upload_img_box").find("tbody").append(table_td);


                layui_uplaod_gload.render({
                    elem: '#upload_id_one_' + a
                    , url: '/public/upload/pic' //上传接口
                    , done: function (res, index, upload) {
                        var item = this.item;
                        if (res.status == 200) {
                            // $('#test-upload-more-list').append('<img src="' + res.data.token + '" alt="' + res.data.token + '" class="layui-upload-img">')

                            item.closest("td").find(".img_input_val").val(res.data.id);
                        } else {
                            layer.msg("上传失败");
                        }
                    }
                });
                layui_uplaod_gload.render({
                    elem: '#upload_id_two_' + a
                    , url: '/public/upload/pic' //上传接口
                    , done: function (res, index, upload) {
                        //获取当前触发上传的元素，一般用于 elem 绑定 class 的情况，注意：此乃 layui 2.1.0 新增
                        var item = this.item;
                        if (res.status == 200) {
                            // $('#test-upload-more-list').append('<img src="' + res.data.token + '" alt="' + res.data.token + '" class="layui-upload-img">')

                            item.closest("td").find(".img_input_val").val(res.data.id);
                        } else {
                            layer.msg("上传失败");
                        }
                    }
                });
                layui_uplaod_gload.render({
                    elem: '#upload_id_third_' + a
                    , url: '/public/upload/pic' //上传接口
                    , done: function (res, index, upload) {
                        //获取当前触发上传的元素，一般用于 elem 绑定 class 的情况，注意：此乃 layui 2.1.0 新增
                        var item = this.item;
                        if (res.status == 200) {
                            // $('#test-upload-more-list').append('<img src="' + res.data.token + '" alt="' + res.data.token + '" class="layui-upload-img">')

                            item.closest("td").find(".img_input_val").val(res.data.id);
                        } else {
                            layer.msg("上传失败");
                        }
                    }
                });
                layui_uplaod_gload.render({
                    elem: '#upload_id_four_' + a
                    , url: '/public/upload/pic' //上传接口
                    , done: function (res, index, upload) {
                        //获取当前触发上传的元素，一般用于 elem 绑定 class 的情况，注意：此乃 layui 2.1.0 新增
                        var item = this.item;
                        if (res.status == 200) {
                            // $('#test-upload-more-list').append('<img src="' + res.data.token + '" alt="' + res.data.token + '" class="layui-upload-img">')

                            item.closest("td").find(".img_input_val").val(res.data.id);
                        } else {
                            layer.msg("上传失败");
                        }
                    }
                });

            }

        } else {

        }


    });

    function uploadfile(uplaodid) {
        layer.msg(uplaodid);
        layui_uplaod_gload.render({
            elem: uplaodid
            , url: '/public/upload/pic' //上传接口
            , done: function (res, index, upload) {
                //获取当前触发上传的元素，一般用于 elem 绑定 class 的情况，注意：此乃 layui 2.1.0 新增
                var item = this.item;
            }
        });
    }


</script>

</body>
</html>


